﻿package
{
	import core.manager.SoundManager;
	import core.Util;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class Title extends MovieClip
	{
		
		public var btn_colour:SimpleButton;//颜色按钮
		public var btn_mute:*;//声音控制
		public var color:MovieClip;
		
		public var btn_help:SimpleButton;//说明
		public var btn_options:SimpleButton;//选项
		
		public var balance:MovieClip;
		
		public var totalstake:TextField;
		
		public function Title()
		{
			
			super();
			this.color.stop();
			this.color.mouseEnabled = false;
			this.addEventListener(MouseEvent.CLICK,checkState);
			btn_mute.buttonMode = btn_mute.useHandCursor = true;
			btn_mute.mouseChildren = false;
			btn_mute.gotoAndStop(3);
		}
		
		public function checkState(event:MouseEvent):void	
		{
			var btn:* = event.target;
			if(btn == btn_colour)
			{
				changeColor();
			}else if(btn == btn_mute){
				SoundManager.instance.pause();
				if(SoundManager.instance.isPause){
					btn_mute.gotoAndStop(4);
				}else {
					btn_mute.gotoAndStop(3);
				}
			}
		}
		
		
		private var colorIndex:int = 1 ;//控制按钮
		
		/**
		 * 一共有三种颜色，蓝色，绿色，红色，默认显示的是蓝色的，点击一次就改变一种颜色，根据三种颜色的顺序
		 * 先要改变自身按钮的颜色 
		 * */
		private function changeColor():void
		{
			colorIndex++;
			if(colorIndex > 3)
			{
				colorIndex = 1;
			}
			this.color.gotoAndStop(colorIndex);
		}
		
		
		public function update(value:Number):void {
			balance.mc_panel.panel.text = value.toFixed(2);
		}
		
		/**
		 * 更新下注的筹码 
		 * @param value
		 * 
		 */		
		public function updateTake(value:Number):void {
			this.totalstake.text = Util.fixedNumber(value,2).toFixed(2);
		}
		
	}
}